<template>
  <div class="isripe">
    <Navi :title="'电影'" :flexd="true" />
    <div class="top">
      <div class="box">
        <div
          class="item"
          v-for="(item, index) in data"
          :key="index"
          @click="goDetails(item.id, false)"
        >
          <div class="imgbox">
            <img class="aimg" :src="item.img" alt="" v-lazy="item.img" />
          </div>
          <div class="tit one-text">{{ item.nm }}</div>
          <div class="ri">上映日期：{{ item.rt }}</div>
          <div class="ren one-text">类型：{{ item.cat }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Navi from "../components/Navi.vue";
export default {
  name: "Isripe",
  components: {
    Navi,
  },
  data() {
    return {
      data: [],
      val: "",
      offset: 20,
    };
  },

  created() {
    this.val = this.$route.params.value;
    
    this.getVideo(this.val, this.offset);
  },
  methods: {
    getVideo(val, offset) {
      this.axios({
        method: "get",
        url: "https://apis.netstart.cn/maoyan/search/movies?&ci=1&",
        params: {
          keyword: val,
          offset: offset,
        },
      })
        .then((result) => {
          this.$toast("加载成功！");
          
          this.data=result.data.movies
        })
        .catch((err) => {
          
        });
    },

    // scrollBottom() {
    //   //加载更多
    //   var scrollTop =
    //     document.documentElement.scrollTop || document.body.scrollTop;
    //   //变量windowHeight是可视区的高度
    //   var windowHeight =
    //     document.documentElement.clientHeight || document.body.clientHeight;
    //   //变量scrollHeight是滚动条的总高度
    //   var scrollHeight =
    //     document.documentElement.scrollHeight || document.body.scrollHeight;
    //   //滚动条到底部的条件
    //   if (scrollTop + windowHeight == scrollHeight && scrollTop > 100) {
    //     //写后台加载数据的函数
    //     this.offset += 20;
    //     this.getVideo(this.val, this.offset);
    //     
    //   }
    // },
    goDetails(id, type) {
      this.$router.push({ name: "Details", params: { id, type } });
    },
  },
  // mounted() {
  //   this.offset = 40;
  //   this.getVideo(this.val, this.offset);
  //   window.addEventListener("scroll", this.scrollBottom);
  // },
  // destroyed() {
  //   window.removeEventListener("scroll", this.scrollBottom);
  // },
};
</script>

<style lang="less" scoped>
.top {
  width: 96%;
  background-color: #fff;
  margin: 0 auto;
  border-radius: 10px;
  .title {
    margin-left: 10px;
    line-height: 50px;
    font-size: 18px;
    font-weight: bold;
    color: #333;
  }
}
.box {
  width: 96%;
  display: flex;
  justify-content: space-between;
  flex-flow: wrap;
  margin: 0 auto;
  padding: 0px 5px 5px;
}
.item {
  width: 48.5%;
  margin-bottom: 10px;
  border-radius: 10px;
  background-color: #fcfafa;
  overflow: hidden;
  padding-bottom: 6px;
  .imgbox {
    width: 100%;
    .aimg {
      width: 100%;
      display: block;
      height: 235px;
    }
  }
  .tit {
    width: 100%;
    font-size: 17px;
    color: #444;
    font-weight: bold;
    margin: 7px 0;
  }
  .ren,
  .ri {
    font-size: 13px;
    color: #444;
    font-weight: bold;
    margin-bottom: 7px;
  }
  .di {
    width: 100%;
    height: 20px;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    padding: 5px 10px 20px;
    box-sizing: border-box;
    text-align: center;
    line-height: 20px;
    .di1 {
      display: flex;
      .tou {
        width: 20px;
        height: 20px;
        margin-right: 5px;
      }
      .text {
        width: 66px;
      }
    }
  }
}
</style>